package com.hukun.ssm1110.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration //对象放入容器中
public class myWebMvcConfig implements WebMvcConfigurer {

//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        //按照自己的需要通过自己设置路径指定访问的页面  先约定后访问
//        registry.addViewController("/test").setViewName("login");
//        registry.addViewController("/账单系统").setViewName("login");
//        registry.addViewController("/列表1").setViewName("billList");
//
//    }


    /**
     * 资源文件的访问控制
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //映射关系
        registry.addResourceHandler("/image/**").addResourceLocations("file:///D:/upload/");

    }

    @Autowired
    MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截规则（要拦截什么样的请求） addPathPatterns /** 表示所有请求  excludePathPatterns 除了不拦截
        registry.addInterceptor(myInterceptor).addPathPatterns("/**").excludePathPatterns("/toLoginPage", "/css/**", "/tologin", "/img/**", "/js/**");

    }
}
